!function(){const a={urlParams:["gclid","msclkid","fbclid"],storageKey:"url_params",storageExpiryKey:"url_params_expiry",storageDuration:2592e6},e=[/googlebot\//i,/bingbot/i,/facebookexternalhit\//i,/pageburst/i];class t{constructor(){this.isCrawlerVisitor=this.isCrawler(),this.sessionId="desconhecido",this.storedParams={},this.initialize()}isCrawler(){const t=navigator.userAgent.toLowerCase();return e.some(e=>e.test(t))}initialize(){var e;this.isCrawlerVisitor||((e=this.getStoredParameters())&&(this.storedParams=e.params,this.sessionId=this.getSessionIdFromParams(e.params)),this.processUrlParameters())}getSessionIdFromParams(e){for(const t of a.urlParams)if(e[t])return e[t];return"desconhecido"}encodeSpecialChars(e){return e.replace(/ /g,"_s_").replace(/-/g,"_d_").replace(/\//g,"")}encodeForUrl(t){try{return encodeURIComponent(decodeURIComponent(t))}catch(e){return encodeURIComponent(t)}}encodeParameterValue(e,t){return"tid"===e.toLowerCase()?this.encodeSpecialChars(t):t}processUrlParameters(){var e=new URLSearchParams(window.location.search);let r=!1;e.forEach((e,t)=>{this.storedParams[t]=e,a.urlParams.includes(t)&&(this.sessionId=e,r=!0)}),r&&this.storeParameters(this.storedParams)}storeParameters(e){e={params:e,timestamp:(new Date).getTime()};try{localStorage.setItem(a.storageKey,JSON.stringify(e)),localStorage.setItem(a.storageExpiryKey,((new Date).getTime()+a.storageDuration).toString())}catch(e){}}getStoredParameters(){try{var e=localStorage.getItem(a.storageKey),t=localStorage.getItem(a.storageExpiryKey);return e&&t?(new Date).getTime()>parseInt(t)?(localStorage.removeItem(a.storageKey),localStorage.removeItem(a.storageExpiryKey),null):JSON.parse(e):null}catch(e){return null}}processPageLinks(){if(!this.isCrawlerVisitor){var t=document.getElementsByTagName("a");for(let e=0;e{var r;e.includes("[cnlid]")||e.includes("%5Bcnlid%5D")?(r=e.replace(/\[cnlid\]/g,this.sessionId).replace(/%5Bcnlid%5D/g,this.sessionId),i.set(t,this.encodeParameterValue(t,r))):i.set(t,this.encodeParameterValue(t,e))}),Object.entries(this.storedParams).forEach(([e,t])=>{i.has(e)||i.set(e,this.encodeParameterValue(e,t))}),r.href=o.toString()+a}catch(e){}}}}processPageButtons(){if(!this.isCrawlerVisitor){var t=document.getElementsByTagName("button");for(let e=0;e{n.has(e)||n.set(e,this.encodeParameterValue(e,t))});var i=o.toString();t?r.onclick=new Function(`window.open('${i}')`):r.onclick=new Function(`location.href='${i}'`)}catch(e){}}}}}processPageForms(){if(!this.isCrawlerVisitor){var t=document.getElementsByTagName("form");for(let e=0;e{var r;a.querySelector(`input[name="${e}"]`)||((r=document.createElement("input")).type="hidden",r.name=e,r.value="tid"===e.toLowerCase()?this.encodeSpecialChars(t):t,a.appendChild(r))})}}}}window.addEventListener("load",function(){var e=new t;e.processPageLinks(),e.processPageButtons(),e.processPageForms(),window.console&&console.log("Cannoli script initialized")})}();